<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../../js/vue.js"></script>
    <script src="../../js/vue-router.js"></script>
</head>

<body>



    <div id="app">
        <router-link to="/user/1">User1</router-link>
        <router-link to="/user/2">User2</router-link>
        <router-link to="/user/3">User3</router-link>
        <!-- 
            <router-link to="/user/...">User...</router-link>
         -->

        <router-view></router-view>
    </div>

    <script>
        const User = {
            // 路由组件中通过 $route.params 来获取到路由参数
            template: '<h1>user{{this.$route.params.id}}组件信息</h1>'
        }

        var router = new VueRouter({
            routes: [
                // 动态路径参数，以冒号开头 
                { path: '/user/:id', component: User }
            ]
        })

        var vm = new Vue({
            el: '#app',
            // 为了能够让路由规则生效，必须把路由对象挂载到vue实例对象上
            router: router
        })
    </script>
</body>

</html>